﻿@model Guid
@section Styles{
    <style type="text/css">
        html, body {
            background: #ffffff;
        }
    </style>
}
@section Scripts{
<input type="hidden" value='@Html.Raw(ViewData["power"])' id="hidden_power" />
<input type="hidden" value='@Model' id="hidden_id" />
<script type="text/javascript">
    var power = JSON.parse(document.getElementById('hidden_power').value);
    var id = document.getElementById('hidden_id').value;
        var app = new Vue({
            el: "#app",
            data: function () {
                return {
                    power: power,
                    prefix: "/Admin/Device",
                    form: {
                        saveState: false,
                        vm: {
                            Id: id,
                            Model: {}
                        }
                    }
                }
            },
            created: function () {
                this.loadForm();
            },
            mounted: function () {

            },
            methods: {
                loadForm: function () {
                    var _this = this;
                    var path = _this.prefix + "/LoadForm/" + _this.form.vm.Id;

                    hzyAdmin.post(path, {}, function (r) {
                        if (r.status != 1) return;
                        _this.form.vm = r.data;
                    });
                },
                closeWindow: function (delay = 0) {
                    setTimeout(function () {
                        hzyAdmin.layer.close(hzyAdmin.layer.getFrameIndex(window.name));
                    }, delay);
                },
                save: function () {
                    var _this = this;
                    var path = _this.prefix + "/Save";

                    //验证
                    //if (!this.form.vm.Model.Function_Name) return hzyAdmin.alert('功能名称不能为空!','警告');

                    this.form.saveState = true;
                    hzyAdmin.post(path, this.form.vm.Model, function (r) {
                        _this.form.saveState = false;
                        if (r.status == 1) {
                            hzyAdmin.alert('保存成功', '成功');
                            //关闭当前窗口
                            _this.closeWindow();
                        }
                    });
                }
            }
        });
    </script>
}
<div class="m-20 hzyAdminForm" id="app">
    <div class="container-fluid">
        <div class="row">

            <div class="col-sm-12">
                <h4 class="example-title">DtuId </h4>
                <input type="text" class="form-control" placeholder="请输入 DtuId " v-model="form.vm.Model.Device_DtuID" autocomplete="off" />
            </div>

            <div class="col-sm-12">
                <h4 class="example-title">在线状态 </h4>
                <el-switch style="display: block"
                           disabled
                           v-model="form.vm.Model.Device_OnlineStatus"
                           active-color="#13ce66"
                           inactive-color="#ff4949"
                           active-text="在线"
                           inactive-text="离线"
                           active-value="1"
                           inactive-value="2">
                </el-switch>
            </div>

            <div class="col-sm-12">
                <h4 class="example-title">设备类型 </h4>
                <el-select v-model="form.vm.Model.Device_DeviceTypeID" placeholder="请选择 设备类型" style="width:100%">
                    <el-option v-for="item in form.vm.deviceTypes"
                               :key="item.DeviceType_ID"
                               :label="item.DeviceType_Name"
                               :value="item.DeviceType_ID">
                    </el-option>
                </el-select>
            </div>

            <div class="col-sm-12">
                <h4 class="example-title">所属终端 </h4>
                <el-select v-model="form.vm.Model.Device_TerminalID" placeholder="请选择 所属终端" style="width:100%">
                    <el-option v-for="item in form.vm.terminals"
                               :key="item.Termial_ID"
                               :label="item.Terminal_Name"
                               :value="item.Terminal_ID">
                    </el-option>
                </el-select>
            </div>

            <div class="col-sm-12">
                <h4 class="example-title">备注 </h4>
                <textarea class="form-control" rows="5" placeholder="请输入 备注" v-model="form.vm.Model.Device_Remarks" autocomplete="off"></textarea>
            </div>

        </div>
        <div class="hzyAdminForm-footer">
            <div class="row">
                <div class="col-sm-6"></div>
                <div class="col-sm-6 text-right">
                    <button class="btn btn-primary" @@click="save" v-bind:disabled="form.saveState" v-if="power.Save">保存</button>
                    <button class="btn btn-danger" @@click="closeWindow()">关闭</button>
                </div>
            </div>
        </div>
    </div>
</div>